<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery1.type" class="el-menu-demo" mode="horizontal" @select="changetab">
      <el-menu-item index="0">全部({{all}})</el-menu-item>
      <el-menu-item index="1">奖励({{rewardCount}})</el-menu-item>
      <el-menu-item index="2">惩罚({{punishmentCount}})</el-menu-item>
      <el-menu-item index="3">已撤销({{revokeCount}})</el-menu-item>
    </el-menu>
    <!--搜索-->
    <el-form :inline="true" :model="listQuery1" size="mini" label-width="80px" style="margin-top:40px;">
      <el-form-item label="员工姓名：">
        <el-input v-model="listQuery1.userName" placeholder="请输入关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          @click="handleSearchList1()"
          type="primary">
          查询
        </el-button>
        <el-button
          @click="showPop3('add','')"
          type="primary">
          新增
        </el-button>
        <el-button
          @click="showImport()"
          type="primary">
          导入
        </el-button>
        <exportPop ref="exportPop" @click.native="downloadExcel"></exportPop>
      </el-form-item>
    </el-form>


    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="listLoading1"
        :data="tableData1"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          label="员工姓名"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>

        <el-table-column
          label="员工工号"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.jobNumber}}
          </template>
        </el-table-column>

        <el-table-column
          label="部门"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.departmentName}}
          </template>
        </el-table-column>

        <el-table-column
          label="岗位"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.job}}
          </template>
        </el-table-column>

        <el-table-column
          label="类型"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.status | fifstatus}}
          </template>
        </el-table-column>

        <el-table-column
          label="奖惩日期"
          min-width="150"
          align="center">
          <template slot-scope="scope">
            {{scope.row.rewardTime}}
          </template>
        </el-table-column>

        <el-table-column
          label="奖惩内容"
          min-width="200"
          align="center">
          <template slot-scope="scope">
            {{scope.row.content}}
          </template>
        </el-table-column>

        <el-table-column
          label="奖惩金额"
          min-width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.money}}
          </template>
        </el-table-column>

        <el-table-column
          label="奖惩原因"
          min-width="200"
          align="center">
          <template slot-scope="scope">
            {{scope.row.reason}}
          </template>
        </el-table-column>

        <el-table-column
          label="是否撤销"
          min-width="100"
          align="center">
          <template slot-scope="scope">
              {{scope.row.revokeStatus  == 2 ? '是' : '否'}}
          </template>
        </el-table-column>

        <el-table-column
          label="撤销备注"
          min-width="200"
          align="center">
          <template slot-scope="scope">
              {{scope.row.revokeRemark}}
          </template>
        </el-table-column>

        <el-table-column
          min-width="150"
          fixed="right"
          label="操作"
          align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              @click="showPop3('edit',scope.row)">编辑
            </el-button>
            <el-button
              v-if="scope.row.revokeStatus == 1"
              type="text"
              size="mini"
              @click="CXJC(scope.row)">撤销
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery1.pageNum"
        :page-size="listQuery1.pageSize"
        :page-sizes="[10,15,20]"
        :total="count1">
      </el-pagination>
    </div>
    <jcpop ref="jcpop" @getShowRewardUser="handleSearchList1"></jcpop>
    <import-pop ref="importPop" @getList="handleSearchList1"></import-pop>
  </div>
</template>
<script>

import {showRewardUser,deleteTrain} from '@/api/company'
import jcpop from './components/jcpop.vue'
import { mapGetters } from 'vuex'
import importPop from "./components/importPop";
import exportPop from "./components/exportPop";
const defaultListQuery1={
  pageNum: 1,
  pageSize: 10,
  userName: '',
  type:'0'
};
export default {
  name: "index",
  components : {
    jcpop:jcpop,
    importPop,
    exportPop
  },
  data(){
    return {
      listQuery1: JSON.parse(JSON.stringify(defaultListQuery1)),
      tableData1: [],
      count1: 0,
      listLoading1: false,
      all:'',
      punishmentCount:'',
      revokeCount:'',
      rewardCount:'',
    }
  },

  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {
      this.getList1()
  },
  filters: {
    fifstatus(val){
      if(val == 1){
          return '奖励'
      }else if(val == 2){
        return '惩罚'
      }
    },
  },
  methods:{
    //显导入弹窗
    showImport(){
      this.$refs.importPop.showImport('importReword','导入员工奖惩记录','/api/user/reword/download')
    },
    downloadExcel(){
      this.$refs.exportPop.downloadExcel('exportUserReward',this.listQuery1)
    },
    //显示新增/编辑奖惩记录
    showPop3(type,item){
      let form = {};
      if(type == 'add'){
        form = {}
      }else{
        form = JSON.parse(JSON.stringify(item))
      }
      this.$refs.jcpop.showPop3(type,form,'list')
    },

    //撤消奖惩
    CXJC(item){
      this.$refs.jcpop.showPop4(item)
    },


    changetab(key){
      this.listQuery1.type = key;
      this.handleSearchList1()
    },
    //获取列表
    getList1() {
      this.listLoading = true;
      let listQuery = JSON.parse(JSON.stringify(this.listQuery1));
      showRewardUser(listQuery).then(response => {
        this.tableData1 = response.list;
        this.count1 = response.count;
        this.listLoading1 = false;
        this.all = response.all;
        this.punishmentCount = response.punishmentCount;
        this.revokeCount = response.revokeCount;
        this.rewardCount = response.rewardCount
      }).catch(()=>{
        this.listLoading1 = false;
      });
    },

    handleSizeChange1(val){
      this.listQuery1.pageNum = 1;
      this.listQuery1.pageSize = val;
      this.getList1();
    },
    handleCurrentChange1(val){
      this.listQuery1.pageNum = val;
      this.getList1();
    },
    handleSearchList1(){
      this.listQuery1.pageNum = 1;
      this.getList1();
    },

  },
}
</script>

<style scoped lang="scss">

</style>
